package com.gao.security.verificationcode;

import com.gao.security.verificationcode.base.BaseVerificationCodeHandler;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import java.util.Map;

/**
 * <p>
 *     VerificationCodeHandler 加载器：多个VerificationCodeHandler实现
 * </p>
 *
 * @author GaoShuangWen
 * @since 2019-07-30 16:08
 */
public class VerificationCodeHandlerLocator implements ApplicationContextAware {
    /**
     * 保存接口实现类名及对应的类
     */
    private Map<String, BaseVerificationCodeHandler> beanMap;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.beanMap= applicationContext.getBeansOfType(BaseVerificationCodeHandler.class);

    }


    public BaseVerificationCodeHandler getBean(String beanName){
        return this.beanMap.get(beanName);
    }
}
